<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loading Animation</title>
    <style>
        .loading {
            --color: #F5F9FF;
            --duration: 2000ms;
            font-family: Roboto, Arial;
            font-size: 24px;
            position: relative;
            white-space: nowrap;
            user-select: none;
            color: var(--color);
        }
        .loading span {
            --x: 0;
            --y: 0;
            --move-y: 0;
            --move-y-s: 0;
            --delay: 0ms;
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 1px;
            text-indent: calc(var(--x) * -1);
            overflow: hidden;
            transform: translate(var(--x), var(--y));
        }
        .loading.start div {
            opacity: 0;
        }
        .loading.start span {
            animation: move var(--duration) ease-in-out var(--delay);
        }

        @keyframes move {
            30% {
                transform: translate(var(--x), var(--move-y));
            }
            82% {
                transform: translate(var(--x), var(--move-y-s));
            }
        }
        html {
            box-sizing: border-box;
            -webkit-font-smoothing: antialiased;
        }

        * {
            box-sizing: inherit;
        }

        body {
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #151924;
        }
        body .dribbble {
            position: fixed;
            display: block;
            right: 20px;
            bottom: 20px;
        }
        body .dribbble img {
            display: block;
            height: 28px;
        }
    </style>
</head>
<body>
<div class="loading">Loading</div>

<script src="https://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script>
    $(document).ready(function() {

        let loading = $('.loading').wrapInner('<div></div>'),
            min = 20,
            max = 70,
            minMove = 10,
            maxMove = 20;

        startAnimation(loading);

        loading.on('animationend webkitAnimationEnd oAnimationEnd', 'span:last-child', e => {
            startAnimation(loading);
        });

        // 设置CSS变量并生成需要的span元素
        function setCSSVars(elem, min, max, minMove, maxMove) {
            let width = Math.ceil(elem.width()),
                text = elem.text();
            for(let i = 1; i < width; i++) {
                let num = Math.floor(Math.random() * (max - min + 1)) + min,
                    numMove = Math.floor(Math.random() * (maxMove - minMove + 1)) + minMove,
                    dir = (i % 2 == 0) ? 1 : -1,
                    spanCurrent = elem.find('span:eq(' + i + ')'),
                    span = spanCurrent.length ? spanCurrent : $('<span />');
                span.css({
                    '--x': i - 1 + 'px',
                    '--move-y': num * dir + 'px',
                    '--move-y-s': ((i % 2 == 0) ? num * dir - numMove : num * dir + numMove) + 'px',
                    '--delay': i * 10 + 'ms'
                });
                if(!spanCurrent.length) {
                    elem.append(span.text(text));
                }
            }
        }

        // 开始动画
        function startAnimation(elem) {
            elem.removeClass('start');
            setCSSVars(elem, min, max, minMove, maxMove);
            void elem[0].offsetWidth;
            elem.addClass('start');
        }

        // 设置加载时间和跳转逻辑
        let t = 3; // 自定义时间为1秒
        setInterval(function() {
            if (t == 0) {
                window.location.href = "../index.html?userId=" + localStorage.getItem("userId") + "&" + encodeURI(localStorage.getItem("userName"));
                //缓冲完成后，页面跳转到首页
            }
            t--; // 自减，实现倒计时
        }, 500); // 每间隔0.5秒钟调用一次函数

    });
</script>
</body>
</html>
